#include "single_list_gp.h"
#include <stdio.h> 


void print_all (linked_list *list)
{
    list_node *ptr = list->head;

    while (ptr != NULL) {
        printf("%d   ", *(int *)(ptr->value));
        ptr = ptr->next;
    }
    printf("\n");
}

int main (int argc, char **argv)
{
    linked_list *list = list_create();
    int a[11] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
    for (int i = 0; i < 10; i++) {
        list = list_add_node_head(list, &a[i]);
    }
    print_all(list);

    list = list_add_node_tail(list, &a[10]);

    print_all(list);

    list_del_node(list, list->head->next->next);
    print_all(list);

    list_node *tmp = list_search_key(list, &a[5]);
    printf("%d\n", *(int *)(tmp->value));

    print_all(list);
    tmp = list_index(list, 8);
    if (tmp == NULL) return 0;
    printf("%d\n", *(int *)(tmp->value));

    list_rewind(list);
    print_all(list);
    printf("toatl is %d\n", list_length(list));

    return 0;
}
